import {getUrlParam,age} from '@/static/js/filter.js'
export default {
	data() {
		return {
			current: 1,
			searchContent: '',
			list: [],
			titleContent: '',
			datas:[],
			healthRank: ''
		}
	},	
	onLoad(option) {
		this.healthRank = localStorage.userInfo && JSON.parse(localStorage.userInfo).healthRank;
		if(getUrlParam('attention')) {
			this.current = 0;
			if(this.current == 0) {
				this.attentionMy()
			} else {
				this.getBdMember()
			}
		}else{
			if(option.enterInto) {
				this.current = 0;
				if(this.current == 0) {
					this.attentionMy()
				} else {
					this.getBdMember()
				}
			}else {
				this.getBdMember();
			}
		}
	},
	watch:{
		$route(v){
			if(this.current == 1){
				this.getBdMember()
			}else{
				this.attentionMy()
			}
		},
		searchContent(val){
			if(val != '') {
				this.titleContent = '取消'
			} else {
				this.titleContent = '';
				
			}
		}
		
	},
	methods: {
		age,
		addQuestion() {
			uni.navigateTo({
				url:'/pages/quickly/user/adduser'
			})
		},
		jump(e) {
			uni.navigateTo({
				url:'/pages/headFeatures/member/memberDetail?userId='+e.userId
			})
		},
		// 关注我的
		AttentionMyjump(e) {
			uni.navigateTo({
				url:'/pages/headFeatures/member/memberDetail?userId='+e.uid+'&id='+e.uhId
			})
		},
		addExperts(item) {
			const expertNoArr = item.expertList && item.expertList.map((res)=>{
				return res.expertNo
			})
			uni.navigateTo({
				url:encodeURI('/pages/headFeatures/member/addExperts?userId='+item.userId+'&expertNoArr='+JSON.stringify(expertNoArr))
			})
		},
		toTell(e){
			uni.makePhoneCall({
				// 手机号
				phoneNumber: e.phone, 
				// 成功回调
				success: (res) => {
					console.log('调用成功!')	
				},
				// 失败回调
				fail: (res) => {
					console.log('调用失败!')
				}
			  });
		},
		// tab栏切换
		clickTab(current) {
			this.current = current
			if(current == 1){
				this.getBdMember()
			}else{
				this.attentionMy()
			}
		},
		// toDetail(item){
		// 	console.log(item)
		// 	const url = item.uid?'/pages/member/memberDetail?id='+item.uid:'/pages/member/memberDetail?id='+item.userId
		// 	uni.navigateTo({
		// 		url:url
		// 	})
		// },
		// 聊天
		toImchat(item){
			const headPicture = item.headPicture || 'http://jlm-file.oss-cn-hangzhou.aliyuncs.com/jlm-product/image/portrait/2020/11/9472ab92fe90400fbee424c2d6b02fb0.png'
			uni.navigateTo({
				url:encodeURI('/pages/imchat/chat?toUserId='+item.codeId+'&name='+item.realName+'&headPicture='+headPicture)
			})
		},
		// 关注会员
		attentionMy() {		
			this.$api.attentionList({pageIndex: 1, pageSize: 20,str: this.searchContent}).then((res) => {
				this.list = res.data.result && res.data.result.list.map((a)=>{
					a.age = age('',a.birthday);
					return a 
				}) || []
			})
		},
		search(){
			this.current == 1?this.getBdMember():this.attentionMy()
		},
		// 付费会员
		getBdMember(){
			this.$api.BdMember({pageIndex: 1, pageSize: 20,str: this.searchContent}).then((res) => {
				this.list = res.data.result && res.data.result.list.map((a)=>{
					a.age = age('',a.birthday);
					return a
				}) || []
			})
		},
		// 关注
		follow(item){
			const _this = this;
			this.$api.addUser({id:item.uhId,userId:item.uid}).then((res)=>{
				if(res.data.returnCode == 200){
					uni.showToast({title: '关注成功',icon:'none',duration:1500,success() {
						_this.attentionMy()
					}});
				}
			})
		},
		// 取消关注
		unfollow(item){
			const _this = this;
			this.$api.cancelUser(item.uhId).then((res)=>{
				if(res.data.returnCode == 200){
					uni.showToast({title: '取消成功',icon:'none',duration:1500,success() {
						_this.attentionMy()
					}});
				}
			})
		},
		cancel() {
			this.searchContent = '';
			if(this.current == 1){
				this.getBdMember()
			}else{
				this.attentionMy()
			}
		}
	}
}